package com.jf.identity.controller;

import com.jf.identity.entity.EmergencyFeedBackInfo;
import com.jf.identity.entity.ExamBaseParam;
import com.jf.identity.entity.ResponseBean;
import com.jf.identity.exception.ServiceException;
import com.jf.identity.service.EmergencyCodeService;
import com.jf.identity.util.Params;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by x on 2018/4/13.
 */
@Controller
@RequestMapping("/cdm/")
public class EmergencyCodeController {
    @Resource
    private EmergencyCodeService emergencyCodeService;

    @RequestMapping(value = "get-emergency-codes")
    @ResponseBody
    public ResponseBean getEmergencyCodes(@RequestBody ExamBaseParam examBaseParam) {

        return new ResponseBean(emergencyCodeService.getEmergencyCods(examBaseParam));
    }

    @RequestMapping(value = "set-exam-emergency-info")
    @ResponseBody
    public ResponseBean setExamEmergencyInfo(@Validated @RequestBody EmergencyFeedBackInfo emergencyFeedBackInfo,
                                             BindingResult bindingResult) {
        Params.beanValidate(bindingResult);
        return new ResponseBean(emergencyCodeService.insertEmergencyFeedBackInfo(emergencyFeedBackInfo));
    }

    @RequestMapping(value = "set-emergency-done")
    @ResponseBody
    public ResponseBean setEmergencyDone(@RequestBody EmergencyFeedBackInfo emergencyFeedBackInfo) {
        if (StringUtils.isEmpty(emergencyFeedBackInfo.getEmergencyReportId())) {
            throw new ServiceException("应急上报事件id不能为空");
        }
        return new ResponseBean(emergencyCodeService.updateEmergencyReportStatus(emergencyFeedBackInfo));
    }
}
